/*
* SMILParser
*
* Version 1.0
*
* Programmers: Jesse Louderback, Noah Pham, Chad Carpenter, and Marc Hindman
*/
package CloudPackage;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.SmilDial.ImageMenu;
import com.SmilDial.SmilDialActivity;
import com.dropbox.client2.DropboxAPI;
import com.dropbox.client2.DropboxAPI.Entry;
import com.dropbox.client2.android.AndroidAuthSession;
import com.dropbox.client2.android.AuthActivity;
import com.dropbox.client2.exception.DropboxException;
import com.dropbox.client2.session.AccessTokenPair;
import com.dropbox.client2.session.AppKeyPair;
import com.dropbox.client2.session.Session.AccessType;
import com.dropbox.client2.session.TokenPair;

public class Cloud extends Activity {
    
	public Cloud()	{}
	        
	public ArrayList<String> getListOfImages() {
		DropboxAPI<AndroidAuthSession> smilDialCloudSession = SmilDialActivity.getInstance();
		ArrayList<String> listOfImages = null;
		
		try {
			String fullPublicURL = "http://dl.dropbox.com/u/40950565/sddProject/images/";
			String IMAGE_DIR = "/Public/sddProject/images/";
			String filePath = "";
			String fileName = "";
			
			// Get the metadata for a directory
            Entry dirent = smilDialCloudSession.metadata(IMAGE_DIR, 1000, null, true, null);
            
			// Make a list of everything in it that we can get a thumbnail for
            listOfImages = new ArrayList<String>();
            
            for (Entry ent: dirent.contents) {
                if (ent.thumbExists) {
                	filePath = ent.path.toString();
                	fileName = filePath.replaceAll(IMAGE_DIR, "");
                	listOfImages.add(fullPublicURL + fileName);
                }
            }            
		} 
		catch (DropboxException e) {
			Log.e("SMILDialLog", "Something went wrong while downloading.");
		}
		
		return listOfImages;
	}
	
	public ArrayList<String> getListOfAudio() {
		DropboxAPI<AndroidAuthSession> smilDialCloudSession = SmilDialActivity.getInstance();
		ArrayList<String> listOfSound = null;
		
		try {
			String SOUND_DIR = "/Public/sddProject/audio/";
			
			// Get the metadata for a directory
            Entry dirent = smilDialCloudSession.metadata(SOUND_DIR, 1000, null, true, null);
            
			// Make a list of everything in it that we can get a thumbnail for
            listOfSound = new ArrayList<String>();
            
            //Add an option 'none' to the menu
            listOfSound.add("none");
            
            //foreach file located in the directory, store the file name into an ArrayList
            for (Entry ent: dirent.contents) {
                listOfSound.add(ent.fileName().replaceAll(".mp3", ""));
            }            
		} catch (DropboxException e) {
			Log.e("SMILDialLog", "Something went wrong while downloading.");
		}
		
		return listOfSound;
	}
}
